package com.mk.carcassonne;

import java.util.ArrayList;
import java.util.HashMap;

import com.mk.carcassonne.drawables.Brick;
import com.mk.carcassonne.drawables.Follower;

public class GlobalData {
	private static Brick _nextBrick;
	private static Brick _lastBrick;
	private static ArrayList<Follower> _placedFollowers;
	private static HashMap<Integer, Integer> _remainingPlayerFollowers;
	private static ArrayList<Position> _brickPlacements;
	private static ArrayList<Brick> _placedBricks;
	private static Boolean _placeFollowerDialogVisible;
	
	public static void init()
	{
		_nextBrick = null;
		_lastBrick = null;
		_placedFollowers = new ArrayList<Follower>();
		_remainingPlayerFollowers = new HashMap<Integer, Integer>();
		_brickPlacements = new ArrayList<Position>();
		_placedBricks = new ArrayList<Brick>();
		_placeFollowerDialogVisible = false;
		
		_remainingPlayerFollowers.put(1, 7);
	}
	
	public static Brick getNextBrick()
	{
		return _nextBrick;
	}
	
	public static Brick getLastBrick()
	{
		return _lastBrick;
	}
	
	public static void setNextBrick(Brick b)
	{
		_lastBrick = _nextBrick;
		_nextBrick = b;
	}
	
	public static void placeFollower(Brick brick, FollowerPlacement placement, Integer playerId)
	{
		Integer remaingFollowers = _remainingPlayerFollowers.get(playerId);
		_remainingPlayerFollowers.put(playerId, remaingFollowers != 0 ? remaingFollowers - 1 : 0);
		_placedFollowers.add(new Follower(brick, placement));
	}

	public static ArrayList<Follower> getPlacedFollowers() {
		return _placedFollowers;
	}

	public static void addPlacedBrick(Brick brick) {
		_placedBricks.add(brick);
	}
	
	public static ArrayList<Brick> getPlacedBricks()
	{
		return _placedBricks;
	}

	public static void addBrickPlacement(Position position) {
		_brickPlacements.add(position);
	}
	
	public static ArrayList<Position> getBrickPlacements()
	{
		return _brickPlacements;
	}
	
	public static void cleanUp() {
		_placedFollowers = null;
		_brickPlacements = null;
		_placedBricks = null;
		_lastBrick = null;
		_nextBrick = null;
	}
	
	public static Integer getRemainingFollowers(Integer playerId)
	{
		return _remainingPlayerFollowers.containsKey(playerId) ? _remainingPlayerFollowers.get(playerId) : 0;
	}

	public static void setPlaceFollowerDialogVisibility(Boolean _placeFollowerDialogVisible)
	{
		GlobalData._placeFollowerDialogVisible = _placeFollowerDialogVisible;
	}

	public static Boolean isPlaceFollowerDialogVisible()
	{
		return _placeFollowerDialogVisible;
	}
}
